﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace Pahan.McuFusion.Common
{
    /// <summary>
    /// Provides information about a microcontroller unit (MCU).
    /// </summary>
    [TypeConverter(typeof(ExpandableObjectConverter))]
    [Serializable]
    public abstract class DeviceInfo
    {
        public abstract String Vendor
        {
            get;
        }

        public abstract String Model
        { 
            get;
        }

        [ReadOnly(true)]
        public virtual String Description
        {
            get;
            protected set;
        }

        public sealed override bool Equals(object obj)
        {
            var other = obj as DeviceInfo;
            if (other == null)
                return false;

            var comparer = StringComparer.InvariantCultureIgnoreCase;
            return comparer.Compare(this.Vendor, other.Vendor) == 0 &&
                comparer.Compare(this.Model, other.Model) == 0;
        }

        public sealed override int GetHashCode()
        {
            return Vendor.ToUpperInvariant().GetHashCode() * 37 +
                Model.ToUpperInvariant().GetHashCode();
        }

        public abstract IList<MemoryClassInfo> Memory
        {
            get;
        }

        public virtual MemoryClassInfo GetMemory(String name)
        {
            return Memory.FirstOrDefault(m => m.Name == name);
        }
    }
}
